﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.SessionState;
using IRepository;

namespace MvcUI.Controllers
{
    public class User
    {
        public string ID { get; set; }
        public string UserName { get; set; }
        public bool Verified { get; set; }
        public static bool IsInRole()
        {
            return false;
        }
    }
    public abstract class BaseController : Controller
    {
        private MvcUI.Controllers.User user;
        protected int pageSize = 20;
       
        public new MvcUI.Controllers.User User
        {
            get { return user; }
        }
        public BaseController()
        {

        }
        protected override void OnAuthorization(AuthorizationContext filterContext)
        {
            user = new MvcUI.Controllers.User();
            if (Session.Keys.Count<1)
            {
                Response.Redirect("~/Account/Index");
            }
            else
            {
                user.UserName = Session["UserName"].ToString();
                user.ID = Session["UserID"].ToString();
                user.Verified = Convert.ToBoolean(Session["Verified"]);
            }
        }

        protected static string SetOperateResultNav(string statusCode, string message, string navTabId, string rel, string callbackType, string closeCurrent, string forwardUrl)
        {
            return "{  \"statusCode\":\"" + statusCode + "\", \"message\":\""+message+"\", \"navTabId\":\""+navTabId+"\", \"rel\":\""+navTabId+"\", \"callbackType\":\""+callbackType+"\",  \"forwardUrl\":\""+forwardUrl+"\"  }";
        }
        protected static string SetOperateResultDialog(string statusCode, string message, string navTabId, string rel, string callbackType, string closeCurrent, string forwardUrl)
        {
            return "{  \"statusCode\":\"" + statusCode + "\", \"message\":\"" + message + "\", \"dialogId\":\"" + navTabId + "\", \"rel\":\"" + navTabId + "\", \"callbackType\":\"" + callbackType + "\",  \"forwardUrl\":\"" + forwardUrl + "\"  }";
        }
    }
}
